//
// Created by Administrator on 2021/11/24.
//

#include "Utils.h"

void Utils::cross_prod(float *c, const float *a, const float *b) {
    float x, y, z;
    x = a[1] * b[2] - b[1] * a[2];
    y = a[2] * b[0] - b[2] * a[0];
    z = a[0] * b[1] - b[0] * a[1];
    c[0] = x;
    c[1] = y;
    c[2] = z;
}

void Utils::normalize(float *norm, const float *a) {
    float len = std::sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
    norm[0] = a[0] / len;
    norm[1] = a[1] / len;
    norm[2] = a[2] / len;
}

void Utils::matrix_mul_vec(float *c, const float *a, const float *b) {
    float x, y, z;
    x = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
    y = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
    z = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
    c[0] = x;
    c[1] = y;
    c[2] = z;
}
